home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Memory / MemInit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  3.1 KB  |  142 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MemInit.cpp
  3.  
  4.     Contains:    CFM initializtion for Memory
  5.  
  6.     Owned by:    A. Michael Burbidge
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <16>      6/7/95    jpa        Removed old (pre-SLIM) SOM includes.
  13.                                     [1256901]
  14.         <15>      6/2/95    TJ        Included Gestalt.h
  15.         <14>      6/1/95    jpa        Restored <12>: Compute total system memory
  16.                                     at init time [1249619]
  17.         <13>     5/17/95    TJ        Backed out changes from previous checkin.
  18.         <11>     1/12/95    jpa        Strings.h --> TextUtils.h [1210936]
  19.         <10>     12/5/94    jpa        Nuked errant pragma lib_export's. [1195676]
  20.          <9>    10/24/94    jpa        Turn off validation
  21.          <8>    10/11/94    NP        1189812: Make Init routine pascal.
  22.          <7>     9/29/94    RA        1189812: Mods for 68K build.
  23.          <6>     9/14/94    jpa        Don't include UseRsrcM.h [1186692]
  24.          <5>      9/9/94    jpa        Added prototype & commented out initBlkPtr
  25.                                     to avoid warnings.
  26.          <4>     8/19/94    jpa        Call ODInitMemory at library init time
  27.                                     [1182106]
  28.          <3>     6/30/94    jpa        Added InitLibraryResources call.
  29.          <2>     6/23/94    NP        Clean up.
  30.          <1>     6/10/94    MB        first checked in
  31.     To Do:
  32.     In Progress:
  33.         
  34. */
  35.  
  36.  
  37. #ifndef __CODEFRAGMENTS__
  38. #include <CodeFragments.h>
  39. #endif
  40.  
  41. #ifndef _MEMMGR_
  42. #include "MemMgr.h"
  43. #endif
  44.  
  45. #ifndef _MEMDEBG_
  46. #include "MemDebg.h"
  47. #endif
  48.  
  49. #ifndef _MEMMGRPV_
  50. #include "MemMgrPv.h"
  51. #endif
  52.  
  53. #ifndef __GESTALT__
  54. #include <Gestalt.h>
  55. #endif
  56.  
  57. #ifndef __ERRORS__
  58. #include <Errors.h>
  59. #endif
  60.  
  61. #ifndef __PROCESSES__
  62. #include <Processes.h>
  63. #endif
  64.  
  65. #ifndef __TEXTUTILS__
  66. #include <TextUtils.h>
  67. #endif
  68.  
  69. #ifndef __SOM__
  70. #include <som.xh>
  71. #endif
  72.  
  73.  
  74. MMBoolean gHaveSOM;
  75.  
  76. size_t gTotalMemory;                // Declared in PlatfMem.h
  77.  
  78.  
  79. static OSErr
  80. GetProcessName( char name[] )
  81. {
  82.     name[0] = 0;
  83.     
  84.     ProcessSerialNumber psn;
  85.     psn.highLongOfPSN = 0;
  86.     psn.lowLongOfPSN = kCurrentProcess;
  87.     
  88.     ProcessInfoRec info;
  89.     info.processInfoLength = sizeof(info);
  90.     info.processName = (StringPtr) name;
  91.     info.processAppSpec = kMMNULL;
  92.     OSErr err= GetProcessInformation(&psn,&info);
  93.     if( !err )
  94.         p2cstr((StringPtr)name);
  95.     return err;
  96. }
  97.  
  98.  
  99. extern "C" {
  100.     pascal OSErr MemoryCFMInit( CFragInitBlockPtr );
  101.     static void* MMCAllocate( size_t size, size_t n );
  102. }
  103.  
  104. static void* MMCAllocate( size_t size, size_t n )
  105. {
  106.     return MMAllocateClear(n*size);
  107. }
  108.  
  109.  
  110. pascal OSErr MemoryCFMInit( CFragInitBlockPtr )
  111. {
  112. #if MM_DEBUG
  113.     long result;
  114.     if( Gestalt(gestaltLogicalRAMSize,(long*)&gTotalMemory) != noErr )
  115.         gTotalMemory = 0x80000000;    // bogus default value
  116.     if( Gestalt(gestaltVMAttr,&result) == noErr && (result&1) )
  117.         gTotalMemory <<= 1;            // Use double logical RAM size if VM on
  118.                                     // since code fragments get loaded above it
  119. #endif
  120.  
  121.     // Create a default heap:
  122.     char name[256];
  123.     GetProcessName(name);
  124.     strcat(name," default heap"); // For debugging only so hardcoded string is OK
  125.     MemHeap *heap = MMNewHeap(kMMTempMemory,200*1024L,32*1024L,name);
  126.     if( !heap )
  127.         return memFullErr;
  128.     MMSetDefaultHeap(heap);
  129.     
  130.     gHaveSOM = ((void*)&SOMMalloc != (void*)kUnresolvedCFragSymbolAddress);    // Is SOM installed?
  131.  
  132.     if( gHaveSOM ) {
  133.         SOMMalloc = &MMAllocate;
  134.         SOMCalloc = &MMCAllocate;
  135.         SOMRealloc= &MMReallocate;
  136.         SOMFree   = &MMFree;
  137.     }
  138.     
  139.     return noErr;
  140. }
  141.  
  142.